package masterMind;

import ewe.fx.Color;
import ewe.fx.Image;
import ewe.fx.mImage;
import ewe.graphics.AniImage;
import ewe.graphics.ImageDragContext;
import ewe.graphics.ImageList;
import ewe.graphics.InteractivePanel;
import ewe.ui.Canvas;

public class Calificacion extends InteractivePanel{

	final int incy = 40;
	final int incx = 35;
	private int n = 5, m=  2;
	public char[] codigo= {'2', '2', '2', '2', '2'};
	
	AniImage[] b = new AniImage[n];
	AniImage[] c = new AniImage[m];
	
	
	void crearColores() {
		Image cols =null;
		for(int i=0;i<m;i++) {
			switch(i) {
				case 0:	cols =new Image("imgs/negrag.png"); 	break;
				case 1: cols =new Image("imgs/blancag.png");	break;
				case 2: cols =new Image("imgs/vacia2.png");		break;
			}			
			cols.transparent = Color.White;
			c[i] =  new AniImage(cols);
			c[i].properties |= AniImage.IsMoveable;	
		}
	}
	
	
	public void addCodeGuess(char[] guess) {
		Image cols ;
		AniImage ai;		
		for(int i=0; i<5; i++) {
			cols =new Image("imgs/"+guess[i]+".png");
			cols.transparent = Color.White;
			ai = new AniImage(cols);		
			ai.location.x = 15+(43*i);
			ai.location.y = 15;
			addImage(ai);			
		}
		refresh();
		
	}
	

	public Calificacion(char[] code)
	{
		
		backGround= ewe.fx.Color.White;
		borderWidth = 2; borderStyle = Canvas.EDGE_SUNKEN;
		addCodeGuess(code);
		touching = new ImageList();
		for(int i=0; i<n; i++) {
			b[i] =  new AniImage(new mImage("imgs/vacia2.png",Color.White));
			b[i].move(15+(i*44), 50);	
			addImage(b[i]);	
			touching.add(b[i]);
		}
		
		
		crearColores();
		for(int i=0; i<m; i++){
			c[i].move(15+(i*25), 100);	
			addImage(c[i]);	
		}
				
	}
	
	public int cual(AniImage A) {
		for(int i=0;i<m; i++) 
			if(A==c[i])
				return i;
		return 0;		
			
	}
		
	public void droppedOn(ImageDragContext dc)
	{
		int c = cual(dc.image);
		for(int i=0; i<n; i++) {
			if (dc.draggingOver == b[i]){						
				b[i].change(dc.image);
				dc.image.move(15+(25*c), 100);
				codigo[i] = (char)(48+c);
				b[i].refresh();
			}	
		}
	
	}
}
